package oj;

/**
 * @author 郝文雪
 * @date 2022/8/10 12:07
 * @Description Test
 */
public class LC733 {
    int c,curColor;
    int[][] dire={{1,0},{0,1},{-1,0},{0,-1}};
    public int[][] floodFill(int[][] image, int sr, int sc, int color) {
        c=color;
        curColor=image[sr][sc];
        if(curColor==c){
            return image;
        }else{
            dfs(image,sr,sc);
        }

        return image;

    }
    private void dfs(int[][] image,int sr,int sc){
        int m=image.length;
        int n=image[0].length;
        if(sr<0 || sr>=m || sc<0 || sr>=n || image[sr][sc]!=curColor || image[sr][sc]==c) return;
        image[sr][sc]=c;
        for(int i=0;i<4;i++){
            int x=sr+dire[i][0];
            int y=sc+dire[i][1];
            dfs(image,x,y);
        }
    }
}
